home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0027_File Copying in DELPHI.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  941 b   |  33 lines

  1.  
  2. I wrote the following function to copy a file and keep the 
  3. attributes/date-time the same on the copied file.  Hope this helps!
  4.  
  5. function FileCopy(source,dest: String): Boolean;
  6. var
  7.   fSrc,fDst,len: Integer;
  8.   size: Longint;
  9.   buffer: packed array [0..2047] of Byte;
  10. begin
  11.   Result := False; { Assume that it WONT work }
  12.   if source <> dest then begin
  13.     fSrc := FileOpen(source,fmOpenRead);
  14.     if fSrc >= 0 then begin
  15.       size := FileSeek(fSrc,0,2);
  16.       FileSeek(fSrc,0,0);
  17.       fDst := FileCreate(dest);
  18.       if fDst >= 0 then begin
  19.         while size > 0 do begin
  20.           len := FileRead(fSrc,buffer,sizeof(buffer));
  21.           FileWrite(fDst,buffer,len);
  22.           size := size - len;
  23.         end;
  24.         FileSetDate(fDst,FileGetDate(fSrc));
  25.         FileClose(fDst);
  26.         FileSetAttr(dest,FileGetAttr(source));
  27.         Result := True;
  28.       end;
  29.       FileClose(fSrc);
  30.     end;
  31.   end;
  32. end;
  33.